1
|
|
|
var GedcomX = require('../'), |
2
|
|
|
utils = require('../utils'); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* An online account for a web application. |
6
|
|
|
* |
7
|
|
|
* @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#online-account|GEDCOM X JSON Spec} |
8
|
|
|
* |
9
|
|
|
* @class |
10
|
|
|
* @extends ExtensibleData |
11
|
|
|
* @param {Object} [json] |
12
|
|
|
*/ |
13
|
|
|
var OnlineAccount = function(json){ |
14
|
|
|
|
15
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
16
|
|
|
if(!(this instanceof OnlineAccount)){ |
17
|
|
|
return new OnlineAccount(json); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
21
|
|
|
if(OnlineAccount.isInstance(json)){ |
22
|
|
|
return json; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
this.init(json); |
|
|
|
|
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
OnlineAccount.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
29
|
|
|
|
30
|
|
|
OnlineAccount._gedxClass = OnlineAccount.prototype._gedxClass = 'GedcomX.OnlineAccount'; |
31
|
|
|
|
32
|
|
|
OnlineAccount.jsonProps = [ |
33
|
|
|
'serviceHomepage', |
34
|
|
|
'accountName' |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Check whether the given object is an instance of this class. |
39
|
|
|
* |
40
|
|
|
* @param {Object} obj |
41
|
|
|
* @returns {Boolean} |
42
|
|
|
*/ |
43
|
|
|
OnlineAccount.isInstance = function(obj){ |
44
|
|
|
return utils.isInstance(obj, this._gedxClass); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize from JSON |
49
|
|
|
* |
50
|
|
|
* @param {Object} |
|
|
|
|
51
|
|
|
* @return {OnlineAccount} this |
52
|
|
|
*/ |
53
|
|
|
OnlineAccount.prototype.init = function(json){ |
54
|
|
|
|
55
|
|
|
GedcomX.ExtensibleData.prototype.init.call(this, json); |
56
|
|
|
|
57
|
|
|
if(json){ |
58
|
|
|
this.setAccountName(json.accountName); |
59
|
|
|
this.setServiceHomepage(json.serviceHomepage); |
60
|
|
|
} |
61
|
|
|
return this; |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the service home page |
66
|
|
|
* |
67
|
|
|
* @returns {ResourceReference} |
68
|
|
|
*/ |
69
|
|
|
OnlineAccount.prototype.getServiceHomepage = function(){ |
70
|
|
|
return this.serviceHomepage; |
71
|
|
|
}; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set the service home page |
75
|
|
|
* |
76
|
|
|
* @param {ResourceReference} serviceHomepage |
77
|
|
|
* @returns {OnlineAccount} |
78
|
|
|
*/ |
79
|
|
|
OnlineAccount.prototype.setServiceHomepage = function(serviceHomepage){ |
80
|
|
|
if(serviceHomepage){ |
81
|
|
|
this.serviceHomepage = GedcomX.ResourceReference(serviceHomepage); |
82
|
|
|
} |
83
|
|
|
return this; |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the account name |
88
|
|
|
* |
89
|
|
|
* @return {String} |
90
|
|
|
*/ |
91
|
|
|
OnlineAccount.prototype.getAccountName = function(){ |
92
|
|
|
return this.accountName; |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set the account name |
97
|
|
|
* |
98
|
|
|
* @param {String} accountName |
99
|
|
|
* @returns {OnlineAccount} |
100
|
|
|
*/ |
101
|
|
|
OnlineAccount.prototype.setAccountName = function(accountName){ |
102
|
|
|
this.accountName = accountName; |
103
|
|
|
return this; |
104
|
|
|
}; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Export the object as JSON |
108
|
|
|
* |
109
|
|
|
* @return {Object} JSON object |
110
|
|
|
*/ |
111
|
|
|
OnlineAccount.prototype.toJSON = function(){ |
112
|
|
|
return this._toJSON(GedcomX.ExtensibleData, OnlineAccount.jsonProps); |
113
|
|
|
}; |
114
|
|
|
|
115
|
|
|
module.exports = OnlineAccount; |